home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr35 / dwnsrs57.zip / DOWNRPT1.C < prev    next >
Text File  |  1993-06-18  |  17KB  |  342 lines

  1. /* ================================================================ */
  2. /*  Rob Hamerling's MAXIMUS download file scan and sort utility     */
  3. /*  -> DOWNRPT1.C                                                   */
  4. /*     Make: BBS-list, New-list, EMI-list                           */
  5. /* ================================================================ */
  6.  
  7. #define INCL_BASE
  8. #define INCL_NOPMAPI
  9. #include <os2.h>
  10.  
  11. #include <conio.h>
  12. #include <memory.h>
  13. #include <string.h>
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16.  
  17. #include "..\max\mstruct.h"
  18. #include "downsort.h"
  19. #include "downfpro.h"
  20.  
  21.  
  22. /* function prototypes of local functions */
  23.  
  24. short int file_age(FILECHAIN *);
  25.  
  26.  
  27. /* --------------------------------------- */
  28. /* Produce the bulletin format of BBS-list */
  29. /* --------------------------------------- */
  30. void make_bbs(struct  _filechain **dm,
  31.               struct  _downpath huge *area,
  32.               unsigned int  x)          /* report privilege index        */
  33. {
  34.   FILE  *pf;                            /* report file handle            */
  35.   char  outfile[MAXFN];                 /* file names                    */
  36.   unsigned int i,j,n,fc;                /* counters                      */
  37.   FILECHAIN *cn;                /* ptr to newest                 */
  38.   short int max_age;                    /* allowed file age in days      */
  39.  
  40.   sprintf(outfile,"%s.%s",lp[P_BBS].name,lp[P_BBS].ext);  /* build fname */
  41.   pf = fopen(outfile,WRITE);            /* output file                   */
  42.   if (pf != NULL) {                     /* successful open               */
  43.     if (oper_mode == VERBOSE)
  44.       fprintf(stdout,MSG_SRT, file_total_count, area_total_count, outfile);
  45.     psort(dm, 0, file_total_count-1, sort_new); /* sort on date          */
  46.     fc = preproc_area(area, dm, lp[P_BBS].priv[x]); /* count files, bytes*/
  47.     cn = NULL;                          /* none assigned                 */
  48.     if (lp[P_BBS].listflag == ' ') {    /* limited by number of entries  */
  49.       n = lp[P_BBS].max_fil;            /* max files to be listed        */
  50.       if (n > fc)                       /* more req'd than within priv   */
  51.         n = fc;                         /* new request-limit             */
  52.       for (i=j=0; j<n && i<file_total_count; ++i)  /* scan limits        */
  53.         if (dm[i]->priv <= lp[P_BBS].priv[x]) { /* check file-privilege  */
  54.           ++j;                          /* count within priv             */
  55.           cn = new_acq(dm[i],cn);       /* most recent within priv       */
  56.           }
  57.       }
  58.     else {                              /* limited by age                */
  59.       max_age = lp[P_BBS].max_fil *
  60.                     ((lp[P_BBS].listflag == 'W') ? 7 :
  61.                      ((lp[P_BBS].listflag == 'M') ? 30 : 1));
  62.       for (i=n=0; file_age(dm[i]) <= max_age &&
  63.                   i<file_total_count; ++i)  /* get report limit          */
  64.         if (dm[i]->priv <= lp[P_BBS].priv[x]) { /* check file-privilege  */
  65.           ++n;                          /* count within priv and age     */
  66.           cn = new_acq(dm[i],cn);       /* most recent within priv       */
  67.           }
  68.       }
  69.     if (lp[P_BBS].sortflag == ALPHA) {  /* re-sort first entries on name */
  70.       if (oper_mode == VERBOSE)
  71.         fprintf(stdout, MSG_RST, n);    /* re-sort msg                   */
  72.       psort(dm, 0, i-1, sort_gbl);      /* re-sort first 'i' entries     */
  73.       }
  74.     if (oper_mode != QUIET)
  75.       fprintf(stdout, MSG_REP, outfile);
  76.     if (oper_mode == VERBOSE)
  77.       fprintf(stdout, MSG_REC);
  78.     lp[P_BBS].incl_fspec = "DOWNSORT.HDR"; /* header filename            */
  79.     file_incl(pf, P_BBS);               /* include bbs-header file       */
  80.  
  81.     fprintf(pf,"\n%c(%s) Last %c%u %s%cnewest of a total of"
  82.                " %c%u%c files (%c%lu%c MB)",
  83.                 O_CYAN, sys_date(today),
  84.                 O_YELLOW, lp[P_BBS].max_fil,
  85.                 (lp[P_BBS].listflag==' ') ? EMPTY :
  86.                  ((lp[P_BBS].listflag=='D') ? DAYS :
  87.                   ((lp[P_BBS].listflag=='W') ? WEEKS : MONTHS)),
  88.                 O_CYAN,
  89.                 O_YELLOW, fc, O_CYAN,
  90.                 O_BRIGHT+O_MAGENTA,
  91.                 (count_bytes(area)/1024+512)/1024,O_CYAN);
  92.  
  93.     if (lp[P_BBS].sortflag == ALPHA &&      /* for filename-sorted list  */
  94.                         cn != NULL)  {      /* new file available        */
  95.       fprintf(pf,"\n%19sNewest: %c%s %c%8s",
  96.                     "", O_YELLOW, cn->fname,
  97.                     O_GREEN,f_date(cn->wdate) );
  98.       fprintf(pf," %c(avail: %c%8s%c)",
  99.                     O_CYAN,O_GREEN,
  100.                     f_date(cn->cdate),O_CYAN);
  101.       }
  102.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  103.                "", DF, DAYS_7, WK, DAYS_30, MO);
  104.     if (lp[P_BBS].exclflag != EXCLPRIV)
  105.       fprintf(pf,"\n\n%c(Your privilege-level may limit the number "
  106.                 "of files actually shown to you!)%c",O_RED,O_CYAN);
  107.     fprintf(pf,"\n\n%c%s       %c%s    %c%s   %c%s    %c%s\n\n",
  108.                 O_YELLOW,FN,
  109.                 O_BRIGHT+O_RED,AC,
  110.                 O_MAGENTA,SZ,
  111.                 O_GREEN,DT,
  112.                 O_CYAN,DS);
  113.     for (i=j=0; j<n && i<file_total_count; i++) {
  114.       if (dm[i]->priv <= lp[P_BBS].priv[x]) {  /* limit to report priv.  */
  115.         if (oper_mode==VERBOSE && (j%25)==0) {
  116.           fprintf(stdout, " %5u\r",j);
  117.           fflush(stdout);
  118.           }
  119.         ++j;                            /* list file-count               */
  120.         fprintf(pf,"%cL%c%c%-12.12s %c%8.8s %c%4ldK %c%s%c %c",
  121.                     '\20',
  122.                     (dm[i]->priv>SYSOP)?'S':priv_name[dm[i]->priv-TWIT][0],
  123.                     O_YELLOW,dm[i]->fname,
  124.                     O_RED+O_BRIGHT,dm[i]->parea->name,
  125.                     O_MAGENTA,(dm[i]->size+1023)/1024,
  126.                     O_GREEN,f_date(dm[i]->wdate),
  127.                     file_age_ind(dm[i]->cdate,dm[i]->ctime),  /* file age*/
  128.                     O_CYAN);
  129.         desc_part(pf, dm[i]->fdesc, 41, 41, P_BBS);  /* file description */
  130.         }
  131.       }
  132.     if (oper_mode==VERBOSE)
  133.       fprintf(stdout, " %5u\n",j);
  134.     signature(pf,today);                /* fingerprint                   */
  135.     lp[P_BBS].incl_fspec = "DOWNSORT.TRL"; /* trailer filename           */
  136.     file_incl(pf, P_BBS);               /* include bbs-trailer file      */
  137.     fclose(pf);                         /* finished with .BBS file       */
  138.     }
  139.   else                                  /* no output possible            */
  140.     fprintf(stderr, MSG_OPO, outfile, 0);
  141.   }
  142.  
  143. /* ------------------------------------------- */
  144. /* Produce the file-request format of NEW-list */
  145. /* ------------------------------------------- */
  146. void make_new(struct  _filechain **dm,
  147.               struct  _downpath huge *area,
  148.               unsigned int x)           /* report priv index             */
  149. {
  150.   FILE  *pf;                            /* file handle                   */
  151.   char  outfile[MAXFN];                 /* file names                    */
  152.   unsigned int i,j,n,fc;                /* counters                      */
  153.   FILECHAIN *cn;                /* ptr to newest                 */
  154.   short int max_age;                    /* allowed file age in days      */
  155.  
  156.   sprintf(outfile,"%s.%s%c",
  157.           lp[P_NEW].name,
  158.           lp[P_NEW].ext,
  159.           priv_name[lp[P_NEW].priv[x]-TWIT][0]);
  160.   pf = fopen(outfile,WRITE);            /* output file                   */
  161.   if (pf != NULL) {                     /* opened!                       */
  162.     if (oper_mode == VERBOSE)
  163.       fprintf(stdout, MSG_SRT, file_total_count, area_total_count, outfile);
  164.     psort(dm, 0, file_total_count-1, sort_new);
  165.     fc = preproc_area(area, dm, lp[P_NEW].priv[x]); /* count file, bytes */
  166.     cn = NULL;                          /* no assigned                   */
  167.     if (lp[P_NEW].listflag == ' ') {    /* limited by number of entries  */
  168.       n = lp[P_NEW].max_fil;            /* take maximum files listed     */
  169.       if (n > fc)                       /* more req'd than within priv   */
  170.         n = fc;                         /* new request-limit             */
  171.       for (i=j=0; j<n && i<file_total_count; ++i)  /* scan limits        */
  172.         if (dm[i]->priv <= lp[P_NEW].priv[x]) { /* check file-privilege  */
  173.           ++j;                          /* count within priv.            */
  174.           cn = new_acq(dm[i],cn);       /* most recent within priv.      */
  175.           }
  176.       }
  177.     else {                              /* limited by age                */
  178.       max_age = lp[P_NEW].max_fil *
  179.                     ((lp[P_NEW].listflag == 'W') ? 7 :
  180.                      ((lp[P_NEW].listflag == 'M') ? 30 : 1));
  181.       for (i=n=0; file_age(dm[i]) <= max_age &&
  182.                   i<file_total_count; ++i)  /* get report limit          */
  183.         if (dm[i]->priv <= lp[P_NEW].priv[x]) { /* check file-privilege  */
  184.           ++n;                          /* count within priv and age     */
  185.           cn = new_acq(dm[i],cn);       /* most recent within priv       */
  186.           }
  187.       }
  188.     if (lp[P_NEW].sortflag == ALPHA) {  /* resort first entries on name  */
  189.       if (oper_mode == VERBOSE)
  190.         fprintf(stdout, MSG_RST, n);    /* re-sort msg                   */
  191.       psort(dm, 0, i-1, sort_gbl);      /* sort first 'i' entries        */
  192.       }
  193.     if (oper_mode != QUIET)
  194.       fprintf(stdout, MSG_REP, outfile);
  195.     if (oper_mode==VERBOSE)
  196.       fprintf(stdout, MSG_REC);
  197.     insert_title(pf, pre_title, 0);
  198.     block_title(pf, 20, list_title, P_NEW);
  199.     file_incl(pf, P_NEW);               /* insert user-'logo'            */
  200.     insert_title(pf, sub_title, 0);
  201.     fprintf(pf,"\n(%s) Last %u %snewest of a total of %u files (%lu MB)",
  202.                  sys_date(today),
  203.                  lp[P_NEW].max_fil,
  204.                 (lp[P_NEW].listflag==' ') ? EMPTY :
  205.                  ((lp[P_NEW].listflag=='D') ? DAYS :
  206.                   ((lp[P_NEW].listflag=='W') ? WEEKS : MONTHS)),
  207.                  fc, (count_bytes(area)/1024+512)/1024);
  208.     if (lp[P_NEW].exclflag != EXCLPRIV)
  209.       fprintf(pf,"\n%19s%s%s",
  210.                "",MP,priv_name[lp[P_NEW].priv[x]-TWIT]);
  211.     if (lp[P_NEW].sortflag == ALPHA &&  /* for filename-sorted list only */
  212.                  cn != NULL) {          /* newest file                   */
  213.       fprintf(pf,"\n%19sNewest: %s dd %8s",
  214.                  "", cn->fname, f_date(cn->wdate));
  215.       fprintf(pf," (avail: %8s)",
  216.                  f_date(cn->cdate));
  217.       }
  218.     fprintf(pf,"\n%19s%s %c%s, %c%s",
  219.                "", DF, DAYS_7, WK, DAYS_30, MO);
  220.     fprintf(pf,"\n\n%s       %s    %s   %s    %s\n",FN,AC,SZ,DT,DS);
  221.     sep_line(pf, '─', 12, 8, 5, 9, 41, 0);
  222.     for (i=j=0; j<n && i<file_total_count; i++) {
  223.       if (dm[i]->priv <= lp[P_NEW].priv[x]) {   /* only upto max priv_lvl*/
  224.         if (oper_mode==VERBOSE && (j%25)==0) {
  225.           fprintf(stdout, " %5u\r", j);
  226.           fflush(stdout);
  227.           }
  228.         ++j;                            /* file list-count               */
  229.         fprintf(pf,"%-12.12s %8.8s %15s ",
  230.               dm[i]->fname,
  231.               dm[i]->parea->name,
  232.               f_size_date(dm[i]->size, dm[i]->wdate,
  233.                           dm[i]->cdate, dm[i]->ctime));
  234.         desc_part(pf, dm[i]->fdesc, 41, 41, P_NEW);  /* file descr.      */
  235.         }
  236.       }
  237.     if (oper_mode==VERBOSE)
  238.       fprintf(stdout," %5u\n",j);
  239.     signature(pf,today);                /* leave fingerprint             */
  240.     insert_title(pf, bot_lines, 0);
  241.     fclose(pf);                         /* finished with .NEW file       */
  242.     }
  243.   else
  244.     fprintf(stderr, MSG_OPO, outfile, 0);
  245.   }
  246.  
  247. /* ------------------------------------------- */
  248. /* Produce the file-request format of EMI-list */
  249. /* This is a more compact variant of NEW-list. */
  250. /* File date, time and size are exact.         */
  251. /* ------------------------------------------- */
  252. void make_emi(struct  _filechain **dm,
  253.               struct  _downpath huge *area,
  254.               unsigned int x)           /* report priv index             */
  255. {
  256.   FILE  *pf;                            /* file handle                   */
  257.   char  outfile[MAXFN];                 /* file names                    */
  258.   unsigned int i,j,n,fc;                /* counters                      */
  259.   FILECHAIN *cn;                /* ptr to newest                 */
  260.   short int max_age;                    /* allowed file age in days      */
  261.  
  262.   sprintf(outfile,"%s.%s%c",
  263.           lp[P_EMI].name,
  264.           lp[P_EMI].ext,
  265.           priv_name[lp[P_EMI].priv[x]-TWIT][0]);
  266.   pf = fopen(outfile,WRITE);            /* output file                   */
  267.   if (pf != NULL) {                     /* opened!                       */
  268.     if (oper_mode == VERBOSE)
  269.       fprintf(stdout,MSG_SRT,file_total_count,area_total_count,outfile);
  270.     psort(dm, 0, file_total_count-1, sort_new);
  271.     fc = preproc_area(area, dm, lp[P_EMI].priv[x]); /* count file, bytes */
  272.     cn = NULL;                          /* no assigned                   */
  273.     if (lp[P_EMI].listflag == ' ') {    /* limited by number of entries  */
  274.       n = lp[P_EMI].max_fil;            /* take maximum files listed     */
  275.       if (n > fc)                       /* more req'd than within priv   */
  276.         n = fc;                         /* new request-limit             */
  277.       for (i=j=0; j<n && i<file_total_count; ++i)  /* scan limits        */
  278.         if (dm[i]->priv <= lp[P_EMI].priv[x]) { /* check file-privilege  */
  279.           ++j;                          /* count within priv.            */
  280.           cn = new_acq(dm[i],cn);       /* most recent within priv.      */
  281.           }
  282.       }
  283.     else {                              /* limited by age                */
  284.       max_age = lp[P_EMI].max_fil *
  285.                     ((lp[P_EMI].listflag == 'W') ? 7 :
  286.                      ((lp[P_EMI].listflag == 'M') ? 30 : 1));
  287.       for (i=n=0; file_age(dm[i]) <= max_age &&
  288.                   i<file_total_count; ++i)  /* get report limit          */
  289.         if (dm[i]->priv <= lp[P_EMI].priv[x]) { /* check file-privilege  */
  290.           ++n;                          /* count within priv and age     */
  291.           cn = new_acq(dm[i],cn);       /* most recent within priv       */
  292.           }
  293.       }
  294.     if (lp[P_EMI].sortflag == ALPHA) {  /* resort first entries on name  */
  295.       if (oper_mode == VERBOSE)
  296.         fprintf(stdout, MSG_RST, n);    /* re-sort msg                   */
  297.       psort(dm, 0, i-1, sort_gbl);      /* sort first 'i' entries        */
  298.       }
  299.     if (oper_mode != QUIET)
  300.       fprintf(stdout, MSG_REP, outfile);
  301.     if (oper_mode==VERBOSE)
  302.       fprintf(stdout, MSG_REC);
  303.     file_incl(pf, P_EMI);               /* insert user text              */
  304.     fprintf(pf,"\n(%s) Last %u %semissions",
  305.                  sys_date(today),
  306.                  lp[P_EMI].max_fil,
  307.                 (lp[P_EMI].listflag==' ') ? EMPTY :
  308.                  ((lp[P_EMI].listflag=='D') ? DAYS :
  309.                   ((lp[P_EMI].listflag=='W') ? WEEKS : MONTHS)));
  310.     fprintf(pf,"\n\n--%s-- --%s--  -%s-  -%s-  ---%s---\n",
  311.                   FN,DT,TM,BY,DS);
  312.     for (i=j=0; j<n && i<file_total_count; i++) {
  313.       if (dm[i]->priv <= lp[P_EMI].priv[x]) {   /* only upto max priv_lvl*/
  314.         if (oper_mode==VERBOSE && (j%25)==0)
  315.           fprintf(stdout, " %5u\r",j);
  316.         ++j;                            /* file list-count */
  317.         fprintf(pf,"%-12.12s %8.8s  %6.6s %8u  ",
  318.               dm[i]->fname,
  319.               f_date(dm[i]->wdate),
  320.               f_time(dm[i]->wtime),
  321.               dm[i]->size);
  322.         desc_part(pf, dm[i]->fdesc, 39, 66, P_EMI);  /* file descr.      */
  323.         }
  324.       }
  325.     if (oper_mode==VERBOSE)
  326.       fprintf(stdout, " %5u\n", j);
  327.     fprintf(pf,"\n-- List created with %s %c.%c%c by %s --\n\n",
  328.                 PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
  329.     fclose(pf);                         /* finished with .EMI file       */
  330.     }
  331.   else
  332.     fprintf(stderr, MSG_OPO, outfile, 0);
  333.   }
  334.  
  335. /* ------------------------------------ */
  336. /* Calculate file-age in number of days */
  337. /* ------------------------------------ */
  338. short int file_age(FILECHAIN *f)
  339. {
  340.   return((short int)((time(NULL) - file_time(f->cdate,f->ctime))/86400L));
  341.   }
  342.